package cn.edu.sjzc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class DataBase {
	Connection conn = null;
	PreparedStatement ps = null;
	ResultSet rs = null;
	String conStr = "jdbc:mysql://192.168.120.37:3306/wuziqi?user=root&password=518";
	String driStr = "com.mysql.jdbc.Driver";

	public int InsertData(String row, String col, String step, String player,
			String errorInfo, String winner, String datetime) {
		int res = 0;
		try {

			Class.forName(driStr);
			conn = DriverManager.getConnection(conStr);
			String sql = "INSERT INTO boardchess(ROW,col,step,player,errorInfo,winner,time)VALUES (?,?,?,?,?,?,?)";
			ps = conn.prepareStatement(sql);
			ps.setString(1, row);
			ps.setString(2, col);
			ps.setString(3, step);
			ps.setString(4, player);
			ps.setString(5, errorInfo);
			ps.setString(6, winner);
			ps.setString(7, datetime);
			res = ps.executeUpdate();
			rs.close();
			ps.close();
			conn.close();

		} catch (Exception e) {

		}
		return res;
	}

	public int dropData(String pos) {
		String[] tempStr = pos.split(",");
		int res = 0;
		try {

			Class.forName(driStr);
			conn = DriverManager.getConnection(conStr);
			String sql = "DELETE FROM boardchess WHERE ROW=? AND col=?";
			ps = conn.prepareStatement(sql);
			ps.setString(1, tempStr[0]);
			ps.setString(2, tempStr[1]);
			res = ps.executeUpdate();
			rs.close();
			ps.close();
			conn.close();

		} catch (Exception e) {

		}
		return res;
	}
}
